# 原始数据
raw_users = [
    "  john DOE  ",
    "ALICE SMITH  ",
    "  bob wilson",
    "Mary-Jane O'Conner"
]
def clean_user_data(users):
    cleaned = []
    for user in users:
        # 去除空格并分割姓名
        clean_name = user.strip()
        
        # 首字母大写
        clean_name = clean_name.title()
        
        # 用下划线替换空格和连字符
        clean_name = clean_name.replace(' ', '_').replace('-', '_')
        
        cleaned.append(clean_name)
    
    return cleaned

# 测试清洗函数
cleaned_users = clean_user_data(raw_users)
print("清洗后的用户数据:")
for user in cleaned_users:
    print(f"  - {user}")
    
 # # Output:清洗后的用户数据:
 #      - John_Doe
 #      - Alice_Smith
 #      - Bob_Wilson
 #      - Mary_Jane_O'Conner
    
    
    cleaned_users_v2 = [
    user.strip().upper().replace(' ', '_')
    for user in raw_users
]

print("\n列表推导式版本:")
for user in cleaned_users_v2:
    print(f"  - {user}")
        
 # # Output:清洗后的用户数据:
 #      - John_Doe
 #      - Alice_Smith
 #      - Bob_Wilson
 #      - Mary_Jane_O'Conner